import { RouteRecordRaw } from "vue-router";
import ZLayout from "@layout/ZLayout.vue";
import EmptyView from "@views/Empty/ZEmpty.vue";
import { getOctpRoutes } from "./octp";
import ZLogin from "@/views/Login/ZLogin.vue";
import { flatRoutes } from "./helpers";
import { getNoPigRoutes } from "./nopig";
import { LOGIN_PAGE_ROUTE_PATH } from "@/utils/constants";

/**
 * ${route.name} 用于 keep-alive 时，与视图组件的name保持一致(vue3中直接以vue文件名做name)
 */

export const getBasicRoutes = (): RouteRecordRaw[] => [
  {
    path: "/",
    component: ZLayout,
    meta: {
      title: "Root",
      hideMenu: true,
    },
    children: [
      {
        path: "home",
        component: () => import("@views/DashBoard/ZDashboard.vue"),
        meta: {
          title: "Home",
          hideFooter: true,
          // hideMenu: true,
          fixed: true,
        },
      },
    ],
  },
  {
    path: LOGIN_PAGE_ROUTE_PATH,
    component: ZLogin,
    meta: {
      title: "Login",
      hideMenu: true,
      hideTab: true,
      hideProgress: true,
    },
  },
  {
    path: "/sys",
    component: ZLayout,
    redirect: "/sys/menu",
    meta: {
      title: "系统管理",
      icon: "SettingsIcon",
    },
    children: [
      {
        path: "menu",
        name: "ZDashboard",
        component: () => import("@views/Dashboard/ZDashboard.vue"),
        meta: {
          title: "菜单管理",
          // rebirth: true,
          // shared: true,
        },
      },
    ],
  },

  {
    path: "/about",
    component: ZLayout,
    redirect: "/about/index",
    meta: {
      title: "关于",
      icon: "InformationIcon",
      orderNo: Infinity,
    },
    children: [
      {
        path: "index",
        name: "ZAbout",
        component: () => import("@views/About/ZAbout.vue"),
        meta: {
          title: "系统信息",
        },
      },
    ],
  },
  {
    path: "/demo",
    component: ZLayout,
    redirect: "/demo/form",
    meta: {
      title: "例子",
      icon: "InformationIcon",
    },
    children: [
      {
        path: "form",
        name: "DemoForm",
        component: () => import("@views/Demo/Form/DemoForm.vue"),
        meta: {
          title: "表单",
        },
      },
      {
        path: "table",
        name: "DemoTable",
        component: () => import("@views/Demo/Table/DemoTable.vue"),
        meta: {
          title: "表格",
        },
      },
      {
        path: "iframe-keepalive",
        name: "DemoIFrameKeepAlive",
        component: EmptyView,
        meta: {
          title: "IframeKeepAlive",
          iframeUrl: "http://127.0.0.1:4200/doc/static/index.html#/",
          hideFooter: true,
        },
      },
      {
        path: "iframe",
        name: "DemoIFrame",
        component: EmptyView,
        meta: {
          title: "Iframe",
          iframeUrl: "http://127.0.0.1:4200/doc/static/index.html#/",
          rebirth: true,
          hideFooter: true,
        },
      },
      {
        path: "upload-chunks",
        name: "ChunksUpload",
        component: () => import("@views/Demo/Upload/ChunksUpload.vue"),
        meta: {
          title: "分片上传",
        },
      },
    ],
  },
];

// tree routes for menus
export const routes = [
  ...getBasicRoutes(),
  ...getOctpRoutes(),
  ...getNoPigRoutes(),
];

// 2-level routes for createRouter
export const flattedRoutes = flatRoutes([
  ...getBasicRoutes(),
  ...getOctpRoutes(),
  ...getNoPigRoutes(),
]);
